package com.musicdaze.utils.schedule;

import java.util.Date;

/**
 * This represents a schedule for the Tasks that
 * has a date, time, and period.
 * @author mfujihara
 *
 */
public class Schedule {
	/** the date */
	private Date date;
	/** the period */
	private long period;
	/** the days of the week to repeat */
	private boolean[] days;
	private int weeks;
	/**
	 * Constructs a Schedule with todays date
	 * that never repeats
	 */
	public Schedule(){
		date = new Date();
		period = 0;
		days = new boolean[7];
	}
	/**
	 * Gets the date
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}
	/**
	 * Gets the period
	 * @return the period. if period == 0, no period. if
	 * period ==-1, then its weekly.  otherwise, its the period.
	 */
	public long getPeriod() {
		return period;
	}
	/**
	 * The number of weeks between repeat
	 * @return the number of weeks between repeats
	 */
	public int getWeeks() {
		return weeks;
	}
	/**
	 * Gets the days repeat
	 * @return the days repeat for the schedule
	 */
	public boolean[] getDaysRepeat(){
		boolean[] copy = new boolean[days.length];
		int i=0;
		for (boolean b : days){
			copy[i]= b;
			i++;
		}
		return copy;
	}
	/**
	 * Sets the date
	 * @param date the date
	 */
	public void setDate(Date date){
		this.date = date;
	}
	/**
	 * Sets the schedule to never repeat
	 */
	public void setNoRepeat(){
		period = 0;
	}
	/**
	 * Sets to repeat every so hours
	 * @param hours the number of hours when to repeat
	 */
	public void setRepeatHourly(int hours){
		period = 60*60*1000*hours;
	}
	/**
	 * Set repeat daily
	 * @param days the number of days to repeat
	 */
	public void setRepeatDaily(int days){
		period = 60*60*1000*24*days;
	}
	/**
	 * Set to repeat weekly
	 * @param weeks the number of weeks to repeat
	 * @param days a boolean array, where each day is true if
	 * its included in the weakly repeat or false if its not 
	 */
	public void setRepeatWeekly(int weeks,boolean[] days){
		period = -1;
		this.weeks = weeks;
		this.days = days;
	}
}
